package com.tianhui.consignortwofei.mvp.ui.activity;

import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.fgs.common.CommonPresenter;
import com.fgs.common.CommonView;
import com.tianhui.consignortwofei.R;
import com.tianhui.consignortwofei.base.BaseActivity;
import com.tianhui.consignortwofei.base.BaseFragment;
import com.tianhui.consignortwofei.constant.Config;
import com.tianhui.consignortwofei.constant.KeyValue;
import com.tianhui.consignortwofei.manager.SharedPreferenceManager;
import com.tianhui.consignortwofei.mvp.model.hetong.ContractInfo;
import com.tianhui.consignortwofei.mvp.ui.activity.hetong.HeTongShenPiBossActivity;
import com.tianhui.consignortwofei.utils.shuiyin.WaterMarkView;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * @author fgs
 * @date 2020/4/28
 * @description
 **/
public class ShenHeWatchOneActivity extends BaseActivity   {


    @BindView(R.id.webview)
    WebView webView;
    @BindView(R.id.wmv)
    WaterMarkView wmv;


    private ContractInfo mContractInfo;

    @Override
    public int getLayoutId() {
        return R.layout.activity_shenhe_watch
                ;
    }

    @Override
    public CommonPresenter createPresenter() {
        return null;
    }

    @Override
    public CommonView createView() {
        return null;
    }

    @Override
    public void init() {
        setTitle("合同");
        Bundle bundle = getIntent().getExtras();
        if (bundle != null && !bundle.isEmpty()) {
            mContractInfo = bundle.getParcelable(KeyValue.KEY_CONTRACT_INFO);
//            LogUtil.print("传递的数据", JsonUtil.toJson(mContractInfo));
//            LogUtil.print("传递的数据===CompanyA",  mContractInfo.company_a);
//            LogUtil.print("传递的数据===contractId",  mContractInfo.id);
        }




        // 启用JavaScript
        webView.getSettings().setJavaScriptEnabled(true);

        // 设置WebView客户端
        webView.setWebViewClient(new WebViewClient());
        webView.getSettings().setSupportZoom(true); // 允许缩放
        webView.getSettings().setBuiltInZoomControls(true);
        webView.getSettings().setDisplayZoomControls(false);// 显示缩放工具栏

        String token = SharedPreferenceManager.getInstance().getToken();
        // 加载网络PDF，使用Google Docs Viewer
//        String pdfUrl = "http://example.com/yourpdf.pdf";

        String pdfUrl = Config.baseUrl+"contract/contractView?fileName="+mContractInfo.contractno+"&token="+token;
        webView.loadUrl("file:///android_asset/indexpdf.html?" + pdfUrl);
//        String pdfUrl ="https://center.haojuntong.com/pdf/web/viewer.html?file=%2Fnladmin%2Fcontract%2FcontractView%3FfileName%3D"+mContractInfo.contractno+"%26token%3D"+token;
//        webView.loadUrl( pdfUrl);
//        Map<String, String> extraHeaders = new HashMap<String, String>();
//        String token = SharedPreferenceManager.getInstance().getToken();
//        extraHeaders.put("token", token);
//        webView.loadUrl(pdfUrl);




//        wmv.setParams("");
//        WebSettings webSettings = webView.getSettings();
//        webSettings.setJavaScriptEnabled(true);
//        webSettings.setAllowFileAccess(true);
//        webSettings.setAllowFileAccessFromFileURLs(true);
//        webSettings.setAllowUniversalAccessFromFileURLs(true);
//
//        webView.loadUrl("http://mozilla.github.io/pdf.js/web/viewer.html?file=" + pdfUrl);

    }

    @Override
    public BaseFragment createFragment() {
        return null;
    }




    @OnClick(R.id.tv_jinshenhe)
    public void newtBu() {
        if (mContractInfo != null) {
            Bundle bundle = new Bundle();
            bundle.putString("danHao", mContractInfo.contractno);
//                            bundle.putParcelable(KeyValue.KEY_CONTRACT_INFO, contractInfo);
//                            openActivity(LiuChengJieDianActivity.class, bundle);//流程显示
            openActivity(HeTongShenPiBossActivity.class, bundle);//审核页面
        }
    }




}
